#ifndef BOX_H
#define BOX_H
#include "shape.h"
#include "point.h"

enum BOX_STATUS
{
    BOX_UNKNOWN,
    BOX_IN,
    BOX_BOUNDARY,
    BOX_CRITICAL,
    BOX_OUT,
    BOX_STAR,
    BOX_POS_END
};

class Box : public Shape
{
public:
    double x0, x1, y0, y1, z0, z1;
    int status;

    Box();
    Box(double _x0, double _x1, double _y0, double _y1, double _z0 = 0, double _z1 = 0);
    Box(const Box& b);

    Box& operator = (const Box& b);

    virtual void draw();

    int getStatus(){return status;}
    void setStatus(int s) {status = s;}

    double width();
    double height();

    bool subdivide(Box* subBox, double threshold);
    bool subdivide4(Box* subBox, double threshold);

    bool isSmall(double threshold);
    bool isPtIn(double x, double y, double z = 0);
    bool contains(Box *box);
    Box intersect(Box *box);
    Box plus(Box *box);

    bool isEmpty();
    bool isPoint();
    bool intersect(double tri[3][2]);
    bool intersect(double *p0, double *p1);
    void getCenter(double *pt);
    void getCenter(Point &pt);
    double radius();
    void getCornerPts(double pt[8][3], int& num);

    bool isPtOnBoundary(double x, double y, double z = 0);

    bool ptInTriangle(double *pt, double tri[3][2]);
    double cross(double *p0, double *p1, double *p2);
    bool segmentIntersect(double p0[2], double p1[2], double p2[2], double p3[2]);
};

extern void drawBox(Box& box);

#endif // BOX_H
